{extend name="common/form" /}
{block name="form"}
<div class="am-u-sm-12 am-u-md-12 am-u-lg-12" style="overflow: hidden">
    <div class="widget am-cf">
        <div class="widget-head am-cf">
            <div class="widget-title am-fl">权限分配</div>
            <div class="widget-function am-fr">
                <a href="javascript:;" class="am-icon-cog"></a>
            </div>
        </div>
        <form>
            <ul class="sidebar-nav">
                {php}
                    function b($data,$access){
                        {/php}
                        <li class="sidebar-nav-link">

                        {php}
                            foreach($data as $value){
                        {/php}
                            <li class="sidebar-nav-link" >
                                <a  class="sidebar-nav-sub-title1" style='position: relative;'>
                                    <span class="am-icon-angle-right sidebar-nav-link-logo"></span>
                                    <label class="am-checkbox-inline">
                                        <input type="checkbox" name="menu[]" value="{$value.id}"
                                               {php}
                                                    if(strstr($access, $value["router_url"])){
                                                    echo "checked";
                                                    }
                                                {/php}
                                               data-am-ucheck>  {$value.name}
                                    </label>
                                </a>

                                    {php}
                                            if($value['son']){
                                    {/php}
                                        <ul class="sidebar-nav sidebar-nav-sub" style="display: block">
                                           {php} b($value['son'],$access);{/php}
                                        </ul>
                                    {php}
                                            }
                                    {/php}

                            </li>

                        {php}
                            }
                        {/php}

                        </li>
                        {php}
                    }
                    b($menuList,$access);
                {/php}
            </ul>
            <input type="hidden" name="role_id" value="{$Request.param.role_id}">
        </form>

        <div class="am-form-group">
            <div class="am-u-sm-12 am-u-sm-push-9">
                <button type="button" onclick="add('{:url($type)}','form')" class="am-btn am-btn-primary tpl-btn-bg-color-success" >
                    提交
                </button>
            </div>
        </div>

    </div>

</div>

{/block}


{block name='script'}
    <script type="text/javascript">

        $('.sidebar-nav-sub-title1').on('click', function(e) {
            if(e.target.tagName == "A"){
                $(this).siblings('.sidebar-nav-sub').slideToggle(80)
                    .end()
                    .stop(false)
                    .find('.sidebar-nav-sub-ico').toggleClass('sidebar-nav-sub-ico-rotate');
            }
        })
        $('.am-checkbox-inline').click(function (e) {
            if(e.target.tagName!="INPUT")
                return;
            var obj =  $(this).parent().parent('li').find('input');
            if($(this).children('input').is(':checked')){
                obj.prop('checked',true);
            }else
                obj.prop('checked',false);
        })
    </script>
{/block}
{extend}